using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using HISModels.Entities;

namespace HISModels.Mapping
{
	public class InsuranceMap : EntityTypeConfiguration<Insurance>
	{
		public InsuranceMap()
		{
			// Primary Key
			this.HasKey(t => t.Id);

			// Properties
			this.Property(t => t.CodeValue)
				.HasMaxLength(50);
				
			this.Property(t => t.NameValue)
				.HasMaxLength(50);
				
			// Table & Column Mappings
			this.ToTable("Insurances");
			this.Property(t => t.Id).HasColumnName("Id");
			this.Property(t => t.HospitalUnitId).HasColumnName("HospitalUnitId");
			this.Property(t => t.CategoryId).HasColumnName("CategoryId");
			this.Property(t => t.CodeValue).HasColumnName("CodeValue");
			this.Property(t => t.NameValue).HasColumnName("NameValue");

			// Relationships
			this.HasOptional(t => t.RefPayerCategory)
				.WithMany(t => t.Insurances)
				.HasForeignKey(d => d.CategoryId);
				
		}
	}
}

